package ca.camosun.morsecode.nongui;
import java.util.HashMap;

import static ca.camosun.morsecode.nongui.MorseConstants.*;
import static ca.camosun.morsecode.nongui.MorseConstants.Index.DOT_DASH;
import static ca.camosun.morsecode.nongui.MorseConstants.Index.LETTER;

import java.util.Map;

public class MorseDecoder {

	public static final String BAD_MORSE = "%";
		
	private Map<String, String> letterMap;
	
	public MorseDecoder() {
		letterMap = new HashMap<String, String>();
		
		for(int i = 0; i < morseLetters.length; i++) {
			letterMap.put(morseLetters[i][DOT_DASH.valueOf()], morseLetters[i][LETTER.valueOf()]);
		}
	}
	
	public String decode(String morseLetter) {
		String realLetter = letterMap.get(morseLetter);
		
		if(realLetter == null) {
			realLetter = BAD_MORSE;
		}
		
		return realLetter;
	}
}
